var app =getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    radioIndex: "男",
  },
  radio: function (e) {
    this.setData({
      radioIndex: e.detail.value,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var bgc = wx.getStorageSync('color')
    var name = options.name
    var id = options.id
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      bgc: bgc,
      name: name,
      id: id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  formSubmit: function (e) {
    var that = this
    var sex = that.data.radioIndex
    var openid = wx.getStorageSync('openid')
    var values = e.detail.value
    var age = values.age
    var gender = values.gender
    var keshi = values.keshi
    var phone = values.phone
    var time = values.time
    var title_content = values.title_content
    var us_name = values.us_name
    var shousmoney = that.data.shousmoney
    console.log(shousmoney)
    var lm_pid = that.data.id
    if (us_name == '') {
      wx.showToast({
        title: '请填写患者名称',
        icon: 'none',
        duration: 2000
      })
    } else if (age == '') {
      wx.showToast({
        title: '请填写患者年龄',
        icon: 'none',
        duration: 2000
      })
    } else if (phone == '') {
      wx.showToast({
        title: '请填写患者联系方式',
        icon: 'none',
        duration: 2000
      })
    } else if (time == '') {
      wx.showToast({
        title: '请选择预约日期',
        icon: 'none',
        duration: 2000
      })
    } else {
      app.util.request({
        'url': 'entry/wxapp/Pay',
        header: {
          "Content-Type": "application/xml"
        },
        method: "GET",
        data: {
          openid: openid,
          z_tw_money: shousmoney
        },
        success: function (res) {
          console.log(res);
          wx.requestPayment({
            'timeStamp': res.data.timeStamp,
            'nonceStr': res.data.nonceStr, //字符串随机数
            'package': res.data.package,
            'signType': res.data.signType,
            'paySign': res.data.paySign,
            success: function (res) {
              app.util.request({
                'url': 'entry/wxapp/Addlmyuyue',
                data: {
                  openid: openid,
                  age: age,
                  sex: gender,
                  keshi: keshi,
                  phone: phone,
                  time: time,
                  title_content: title_content,
                  us_name: us_name,
                  paymoney: that.data.shousmoney,
                  lm_pid: lm_pid
                },
                success: function (res) {
                  wx.showToast({
                    title: '提交成功',
                    icon: 'success',
                    duration: 3000,
                    success: function () {
                      wx.reLaunch({
                        url: '/hyb_yl/tabBar/index/index',
                      })
                    }
                  })
                }
              })
            }
          })
        }
      })
    }

  },
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
  },
})